package br.com.puertorico.mecanismos.ui.validators;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import br.com.puertorico.common.utils.DateFacility;

/**
 * Classe para validar se uma data &eacute; maior ou igual &agrave; data atual
 * no JSF.
 */
public class DataFuturaValidator extends BaseValidator implements Validator {

	@Override
	public void validate(FacesContext ctx, UIComponent comp, Object value)
			throws ValidatorException {
		if (!(value instanceof Date)) {

		}
		Date current = DateFacility.zerarTempo(new Date());
		Date data = DateFacility.zerarTempo((Date) value);

		if (data.before(current)) {
			String newValue = DateFacility.formatDate(data,
					DateFacility.PATTERN_BR_SMALL);
			FacesMessage facesMsg = new FacesMessage(
					FacesMessage.SEVERITY_ERROR, "", getMessage(newValue));
			throw new ValidatorException(facesMsg);
		}
	}

}
